package lesson.myset;

import java.util.Comparator;
import java.util.TreeSet;

public class MyTreeSet2 {
    public static void main(String[] args) {
//        TreeSet<Student> ts = new TreeSet<>(new Comparator<Student>() {
//            @Override
//            public int compare(Student o1, Student o2) {
//                int result = o1.getAge() - o2.getAge();
//                result = result==0? o1.getName().compareTo(o2.getName()) :result;
//                return  result;
//
//            }
//        });

        TreeSet<Student> ts = new TreeSet<>(
                ( o1,  o2)->{
                    int result = o1.getAge() - o2.getAge();
                    return result == 0?o1.getName().compareTo(o2.getName()):result;
                }
        );

        Student s1 = new Student("张三",27);
        Student s2 = new Student("李四",28);
        Student s3 = new Student("王五",27);

        ts.add(s1);
        ts.add(s2);
        ts.add(s3);

        System.out.println(ts);
    }
}
